import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../flutter_widgets.dart';

Future<int?> showPicker(
  BuildContext context,
  List<String> data,
  int currentIndex, {
  ValueChanged<int>? onSelectedItemChanged,
}) {
  final scrollController =
      FixedExtentScrollController(initialItem: currentIndex);

  return showModalBottomSheet(
    context: context,
    builder: (context) {
      return Scaffold(
        appBar: CommonAppBar(
          actions: <Widget>[
            CommonFlatButton(
              text: '确定',
              onPressed: () {
                Navigator.of(context).pop(scrollController.selectedItem);
              },
            )
          ],
        ),
        body: CupertinoPicker(
          backgroundColor: Colors.white,
          magnification: 1.14,
          useMagnifier: true,
          scrollController: scrollController,
          itemExtent: 48,
          //height of each item
          onSelectedItemChanged: onSelectedItemChanged,
          children: data
              .map(
                (item) => SizedBox(
                  height: 48,
                  child: Center(
                    child: Text(
                      item,
                      style: Theme.of(context).textTheme.titleMedium,
                    ),
                  ),
                ),
              )
              .toList(),
        ),
      );
    },
  );
}
